const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
	mode: "development",
	entry: "./src/main.js",
	output: {
		path: path.resolve(__dirname, "dist"),
		filename: "bundle.js",
		publicPath: "/",
	},
	module: {
		rules: [
			{
				test: /\.vue$/,
				loader: "vue-loader",
			},
			{
				test: /\.js$/,
				loader: "babel-loader",
				exclude: /node_modules/,
			},
			{
				test: /\.css$/,
				use: ["style-loader", "css-loader"],
			},
			{
				test: /\.scss|sass$/,
				use: ["style-loader", "css-loader", "sass-loader"],
			},
			{
				test: /\.(png|jpg|gif|svg)$/,
				type: "asset/resource",
				generator: {
					filename: "assets/images/[hash][ext][query]",
				},
			},
			{
				test: /\.(woff|woff2|eot|ttf|otf)$/,
				type: "asset/resource",
				generator: {
					filename: "assets/fonts/[hash][ext][query]",
				},
			},
		],
	},
	plugins: [
		new VueLoaderPlugin(),
		new HtmlWebpackPlugin({
			template: "./public/index.html",
			filename: "index.html",
			title: "积分管理系统",
		}),
	],
	devServer: {
		static: {
			directory: path.join(__dirname, "public"),
		},
		historyApiFallback: true,
		hot: true,
		port: 8080,
		open: true,
	},
	resolve: {
		extensions: [".js", ".vue", ".json"],
		alias: {
			"@": path.resolve(__dirname, "src"),
			vue$: "vue/dist/vue.esm.js",
		},
	},
};
